
 <!DOCTYPE HTML>
<html lang="en">
<head>
  <meta charset="UTF-8">
  
    <title>外星人入侵 | 冈崎汐峰的博客</title>
    <meta name="viewport" content="width=device-width, initial-scale=1,user-scalable=no">
    
    <meta name="author" content="冈崎汐峰">
    

    
    <meta name="description" content="外星人入侵（未完成）因初次接触面向对象的编程语言，学习并不深刻，无法继续进行，我将在以后更加努力学习，从而完成这个项目 alien_invasion1234567891011121314151617181920212223242526import pygamefrom settings import Settingsfrom ship import Shipimport game_function">
<meta property="og:type" content="article">
<meta property="og:title" content="外星人入侵">
<meta property="og:url" content="http://yoursite.com/2020/04/04/%E5%A4%96%E6%98%9F%E4%BA%BA%E5%85%A5%E4%BE%B5/index.html">
<meta property="og:site_name" content="冈崎汐峰的博客">
<meta property="og:description" content="外星人入侵（未完成）因初次接触面向对象的编程语言，学习并不深刻，无法继续进行，我将在以后更加努力学习，从而完成这个项目 alien_invasion1234567891011121314151617181920212223242526import pygamefrom settings import Settingsfrom ship import Shipimport game_function">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2020-04-04T09:32:41.184Z">
<meta property="article:modified_time" content="2020-04-04T09:32:20.520Z">
<meta property="article:author" content="冈崎汐峰">
<meta name="twitter:card" content="summary">

    
    <link rel="alternative" href="/atom.xml" title="冈崎汐峰的博客" type="application/atom+xml">
    
    
    <link rel="icon" href="/img/favicon.ico">
    
    
    <link rel="apple-touch-icon" href="/img/jacman.jpg">
    <link rel="apple-touch-icon-precomposed" href="/img/jacman.jpg">
    
    
<link rel="stylesheet" href="/css/style.css">
<link rel="stylesheet" href="/%02.css">
<link rel="stylesheet" href="/.css">

<meta name="generator" content="Hexo 4.2.0"></head>

  <body>
    <header>
      
<div>
		
			<div id="imglogo">
				<a href="/"><img src="/img/logo.png" alt="冈崎汐峰的博客" title="冈崎汐峰的博客"/></a>
			</div>
			
			<div id="textlogo">
				<h1 class="site-name"><a href="/" title="冈崎汐峰的博客">冈崎汐峰的博客</a></h1>
				<h2 class="blog-motto"></h2>
			</div>
			<div class="navbar"><a class="navbutton navmobile" href="#" title="Menu">
			</a></div>
			<nav class="animated">
				<ul>
					<ul>
					 
						<li><a href="/">Home</a></li>
					
						<li><a href="/archives">Archives</a></li>
					
						<li><a href="/about">About</a></li>
					
					<li>
 					
					<form class="search" action="//google.com/search" method="get" accept-charset="utf-8">
						<label>Search</label>
						<input type="search" id="search" name="q" autocomplete="off" maxlength="20" placeholder="Search" />
						<input type="hidden" name="q" value="site:yoursite.com">
					</form>
					
					</li>
				</ul>
			</nav>			
</div>
    </header>
    <div id="container">
      <div id="main" class="post" itemscope itemprop="blogPost">
  
	<article itemprop="articleBody"> 
		<header class="article-info clearfix">
  <h1 itemprop="name">
    
      <a href="/2020/04/04/外星人入侵/" title="外星人入侵" itemprop="url">外星人入侵</a>
  </h1>
  <p class="article-author">By
       
		<a href="/about" title="冈崎汐峰" target="_blank" itemprop="author">冈崎汐峰</a>
		
  <p class="article-time">
    <time datetime="2020-04-04T09:32:41.184Z" itemprop="datePublished"> Published 2020-04-04</time>
    
  </p>
</header>
	<div class="article-content">
		
		<div id="toc" class="toc-article">
			<strong class="toc-title">Contents</strong>
		
			<ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#外星人入侵（未完成）"><span class="toc-number">1.</span> <span class="toc-text">外星人入侵（未完成）</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#alien-invasion"><span class="toc-number">1.1.</span> <span class="toc-text">alien_invasion</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#game-functions"><span class="toc-number">1.2.</span> <span class="toc-text">game_functions</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#settings"><span class="toc-number">1.3.</span> <span class="toc-text">settings</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#ship"><span class="toc-number">1.4.</span> <span class="toc-text">ship</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#bullet"><span class="toc-number">1.5.</span> <span class="toc-text">bullet</span></a></li></ol></li></ol>
		
		</div>
		
		<h1 id="外星人入侵（未完成）"><a href="#外星人入侵（未完成）" class="headerlink" title="外星人入侵（未完成）"></a>外星人入侵（未完成）</h1><p>因初次接触面向对象的编程语言，学习并不深刻，无法继续进行，我将在以后更加努力学习，从而完成这个项目</p>
<h2 id="alien-invasion"><a href="#alien-invasion" class="headerlink" title="alien_invasion"></a>alien_invasion</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> pygame</span><br><span class="line"></span><br><span class="line"><span class="keyword">from</span> settings <span class="keyword">import</span> Settings</span><br><span class="line"><span class="keyword">from</span> ship <span class="keyword">import</span> Ship</span><br><span class="line"><span class="keyword">import</span> game_functions <span class="keyword">as</span> gf</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">run_game</span><span class="params">()</span>:</span></span><br><span class="line">    <span class="comment"># 初始化游戏并创建一个屏幕对象</span></span><br><span class="line">    pygame.init()</span><br><span class="line">    ai_settings = Settings()</span><br><span class="line">    screen = pygame.display.set_mode(</span><br><span class="line">        (ai_settings.screen_width, ai_settings.screen_height)</span><br><span class="line">    )</span><br><span class="line">    pygame.display.set_caption(<span class="string">"Alien Invasion"</span>)</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 创建一艘飞船</span></span><br><span class="line">    ship = Ship(ai_settings,screen)</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 开始游戏的主循环</span></span><br><span class="line">    <span class="keyword">while</span> <span class="literal">True</span>:</span><br><span class="line">        gf.check_events(ship)</span><br><span class="line">        ship.update()</span><br><span class="line">        gf.update_screen(ai_settings,screen,ship)</span><br><span class="line"></span><br><span class="line">run_game()</span><br></pre></td></tr></table></figure>

<h2 id="game-functions"><a href="#game-functions" class="headerlink" title="game_functions"></a>game_functions</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> sys</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> pygame</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">check_keydown_events</span><span class="params">(event,ship)</span>:</span></span><br><span class="line">    <span class="string">"""响应按键"""</span></span><br><span class="line">    <span class="keyword">if</span> event.key == pygame.K_RIGHT:</span><br><span class="line">        ship.moving_right = <span class="literal">True</span></span><br><span class="line">    <span class="keyword">elif</span> event.key == pygame.K_LEFT:</span><br><span class="line">        ship.moving_left = <span class="literal">True</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">check_keyup_events</span><span class="params">(event,ship)</span>:</span></span><br><span class="line">    <span class="string">"""响应松开"""</span></span><br><span class="line">    <span class="keyword">if</span> event.key == pygame.K_RIGHT:</span><br><span class="line">        ship.moving_right = <span class="literal">False</span></span><br><span class="line">    <span class="keyword">elif</span> event.key == pygame.K_LEFT:</span><br><span class="line">        ship.moving_left = <span class="literal">False</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">check_events</span><span class="params">(ship)</span>:</span></span><br><span class="line">    <span class="string">"""响应按键和鼠标事件"""</span></span><br><span class="line">    <span class="keyword">for</span> event <span class="keyword">in</span> pygame.event.get():</span><br><span class="line">        <span class="keyword">if</span> event.type == pygame.QUIT:</span><br><span class="line">            sys.exit()</span><br><span class="line">        <span class="keyword">elif</span> event.type == pygame.KEYDOWN:</span><br><span class="line">            check_keydown_events(event,ship)</span><br><span class="line">        <span class="keyword">elif</span> event.type ==pygame.KEYUP:</span><br><span class="line">            check_keyup_events(event,ship)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">update_screen</span><span class="params">(ai_settings,screen,ship)</span>:</span></span><br><span class="line">    <span class="string">"""更新屏幕上的图像，并切换到新屏幕"""</span></span><br><span class="line">    <span class="comment"># 每次循环都重新绘制屏幕</span></span><br><span class="line">    screen.fill(ai_settings.bg_color)</span><br><span class="line">    ship.blitme()</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 让最近绘制的屏幕可见</span></span><br><span class="line">    pygame.display.flip()</span><br></pre></td></tr></table></figure>
<h2 id="settings"><a href="#settings" class="headerlink" title="settings"></a>settings</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Settings</span><span class="params">()</span>:</span></span><br><span class="line">    <span class="string">"""存储《外星人入侵》的所有设置的类"""</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span><span class="params">(self)</span>:</span></span><br><span class="line">        <span class="string">"""初始化游戏的设置"""</span></span><br><span class="line">        <span class="comment"># 屏幕设置</span></span><br><span class="line">        self.screen_width = <span class="number">1200</span></span><br><span class="line">        self.screen_height = <span class="number">800</span></span><br><span class="line">        self.bg_color = (<span class="number">230</span>,<span class="number">230</span>,<span class="number">230</span>)</span><br><span class="line">        <span class="comment"># 飞船的设置</span></span><br><span class="line">        self.ship_speed_factor = <span class="number">1.5</span></span><br><span class="line">        <span class="comment"># 子弹设置</span></span><br><span class="line">        self.bullet_speed_factor = <span class="number">1</span></span><br><span class="line">        self.bullet_width = <span class="number">3</span></span><br><span class="line">        self.bullet_height = <span class="number">15</span></span><br><span class="line">        self.bullet_color = <span class="number">60</span>,<span class="number">60</span>,<span class="number">60</span></span><br></pre></td></tr></table></figure>
<h2 id="ship"><a href="#ship" class="headerlink" title="ship"></a>ship</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> pygame</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Ship</span><span class="params">()</span>:</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span><span class="params">(self,ai_settings,screen)</span>:</span></span><br><span class="line">        <span class="string">"""初始化飞船并设置其初始位置"""</span></span><br><span class="line">        self.screen = screen</span><br><span class="line">        self.ai_settings = ai_settings</span><br><span class="line">        <span class="comment"># 加载飞船图像并获取其外接矩形</span></span><br><span class="line">        self.image = pygame.image.load(<span class="string">r"E:\py\外星人入侵\images\ship.bmp"</span>)</span><br><span class="line">        self.rect = self.image.get_rect()</span><br><span class="line">        self.screen_rect = screen.get_rect()</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 将每一艘新飞船放在屏幕底部中央</span></span><br><span class="line">        self.rect.centerx = self.screen_rect.centerx</span><br><span class="line">        self.rect.bottom = self.screen_rect.bottom</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 在飞船的属性center中存储小数值</span></span><br><span class="line">        self.center = float(self.rect.centerx)</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 移动标志</span></span><br><span class="line">        self.moving_right = <span class="literal">False</span></span><br><span class="line">        self.moving_left = <span class="literal">False</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">update</span><span class="params">(self)</span>:</span></span><br><span class="line">        <span class="string">"""根据移动标志调整飞船的位置"""</span></span><br><span class="line">        <span class="comment"># 更新飞船center的值，而不是rect</span></span><br><span class="line">        <span class="keyword">if</span> self.moving_right <span class="keyword">and</span> self.rect.right &lt; self.screen_rect.right:</span><br><span class="line">            self.center += self.ai_settings.ship_speed_factor</span><br><span class="line">        <span class="keyword">if</span> self.moving_left <span class="keyword">and</span> self.rect.left &gt; <span class="number">0</span>:</span><br><span class="line">            self.center -= self.ai_settings.ship_speed_factor</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 根据self.center更新rect对象</span></span><br><span class="line">        self.rect.centerx = self.center</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">blitme</span><span class="params">(self)</span>:</span></span><br><span class="line">        <span class="string">"""在指定位置绘制飞船"""</span></span><br><span class="line">        self.screen.blit(self.image,self.rect)</span><br></pre></td></tr></table></figure>
<h2 id="bullet"><a href="#bullet" class="headerlink" title="bullet"></a>bullet</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> pygame</span><br><span class="line"><span class="keyword">from</span> pygame.sprite <span class="keyword">import</span> Sprite</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Bullet</span><span class="params">(Sprite)</span>:</span></span><br><span class="line">    <span class="string">"""一个对飞船发射的子弹进行管理的类"""</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span><span class="params">(self,ai_settings,screen,ship)</span>:</span></span><br><span class="line">        <span class="string">"""在飞船所处的位置创建一个子弹对象"""</span></span><br><span class="line">        super(Bullet,self).__init__()</span><br><span class="line">        self.screen = screen</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 在(0,0)处创建一个表示子弹的矩形，再设置正确的位置</span></span><br><span class="line">        self.rect = pygame.Rect(<span class="number">0</span>,<span class="number">0</span>,ai_settings.bullet_width,ai_settings.bullet_height)</span><br><span class="line">        self.rect.centerx = ship.rect.centerx</span><br><span class="line">        self.rect.top = ship.rect.top</span><br><span class="line">        <span class="comment"># 存储用小数表示的子弹位置</span></span><br><span class="line">        self.y = float(self.rect.y)</span><br><span class="line"></span><br><span class="line">        self.color = ai_settings.bullet_color</span><br><span class="line">        self.speed_factor = ai_settings.bullet_speed_factor</span><br></pre></td></tr></table></figure>
  
	</div>
		<footer class="article-footer clearfix">
<div class="article-catetags">


</div>



	<div class="article-share" id="share">
	
	  <div data-url="http://yoursite.com/2020/04/04/%E5%A4%96%E6%98%9F%E4%BA%BA%E5%85%A5%E4%BE%B5/" data-title="外星人入侵 | 冈崎汐峰的博客" data-tsina="" class="share clearfix">
	  </div>
	
	</div>


</footer>

   	       
	</article>
	
<nav class="article-nav clearfix">
 
 <div class="prev" >
 <a href="/2020/04/04/测试代码/" title="测试代码">
  <strong>上一篇：</strong><br/>
  <span>
  测试代码</span>
</a>
</div>


<div class="next">
<a href="/2020/03/28/第一个博客/"  title="第一个博客">
 <strong>下一篇：</strong><br/> 
 <span>第一个博客
</span>
</a>
</div>

</nav>

	



</div>  
      <div class="openaside"><a class="navbutton" href="#" title="Show Sidebar"></a></div>

  <div id="toc" class="toc-aside">
  <strong class="toc-title">Contents</strong>
 
 <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#外星人入侵（未完成）"><span class="toc-number">1.</span> <span class="toc-text">外星人入侵（未完成）</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#alien-invasion"><span class="toc-number">1.1.</span> <span class="toc-text">alien_invasion</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#game-functions"><span class="toc-number">1.2.</span> <span class="toc-text">game_functions</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#settings"><span class="toc-number">1.3.</span> <span class="toc-text">settings</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#ship"><span class="toc-number">1.4.</span> <span class="toc-text">ship</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#bullet"><span class="toc-number">1.5.</span> <span class="toc-text">bullet</span></a></li></ol></li></ol>
 
  </div>

<div id="asidepart">
<div class="closeaside"><a class="closebutton" href="#" title="Hide Sidebar"></a></div>
<aside class="clearfix">

  


  

  

  <div class="linkslist">
  <p class="asidetitle">Links</p>
    <ul>
        
          <li>
            
            	<a href="https://coderq.com" target="_blank" title="一个面向程序员交流分享的新一代社区">码农圈</a>
            
          </li>
        
          <li>
            
            	<a href="http://wuchong.me" target="_blank" title="Jark&#39;s Blog">Jark&#39;s Blog</a>
            
          </li>
        
    </ul>
</div>

  


  <div class="rsspart">
	<a href="/atom.xml" target="_blank" title="rss">RSS</a>
</div>

  <div class="weiboshow">
  <p class="asidetitle">Weibo</p>
    <iframe width="100%" height="119" class="share_self"  frameborder="0" scrolling="no" src="http://widget.weibo.com/weiboshow/index.php?language=&width=0&height=119&fansRow=2&ptype=1&speed=0&skin=9&isTitle=1&noborder=1&isWeibo=0&isFans=0&uid=&verifier=b3593ceb&dpc=1"></iframe>
</div>


</aside>
</div>
    </div>
    <footer><div id="footer" >
	
	<div class="line">
		<span></span>
		<div class="author"></div>
	</div>
	
	
	<section class="info">
		<p> Hello ,I&#39;m Larry Page in Google. <br/>
			This is my blog,believe it or not.</p>
	</section>
	 
	<div class="social-font" class="clearfix">
		
		<a href="http://weibo.com/2176287895" target="_blank" class="icon-weibo" title="微博"></a>
		
		
		
		
		
		
		
		
		
		
	</div>
			
		

		<p class="copyright">
		Powered by <a href="http://hexo.io" target="_blank" title="hexo">hexo</a> and Theme by <a href="https://github.com/wuchong/jacman" target="_blank" title="Jacman">Jacman</a> © 2020 
		
		<a href="/about" target="_blank" title="冈崎汐峰">冈崎汐峰</a>
		
		
		</p>
</div>
</footer>
    <script src="/js/jquery-2.0.3.min.js"></script>
<script src="/js/jquery.imagesloaded.min.js"></script>
<script src="/js/gallery.js"></script>
<script src="/js/jquery.qrcode-0.12.0.min.js"></script>

<script type="text/javascript">
$(document).ready(function(){ 
  $('.navbar').click(function(){
    $('header nav').toggleClass('shownav');
  });
  var myWidth = 0;
  function getSize(){
    if( typeof( window.innerWidth ) == 'number' ) {
      myWidth = window.innerWidth;
    } else if( document.documentElement && document.documentElement.clientWidth) {
      myWidth = document.documentElement.clientWidth;
    };
  };
  var m = $('#main'),
      a = $('#asidepart'),
      c = $('.closeaside'),
      o = $('.openaside');
  c.click(function(){
    a.addClass('fadeOut').css('display', 'none');
    o.css('display', 'block').addClass('fadeIn');
    m.addClass('moveMain');
  });
  o.click(function(){
    o.css('display', 'none').removeClass('beforeFadeIn');
    a.css('display', 'block').removeClass('fadeOut').addClass('fadeIn');      
    m.removeClass('moveMain');
  });
  $(window).scroll(function(){
    o.css("top",Math.max(80,260-$(this).scrollTop()));
  });
  
  $(window).resize(function(){
    getSize(); 
    if (myWidth >= 1024) {
      $('header nav').removeClass('shownav');
    }else{
      m.removeClass('moveMain');
      a.css('display', 'block').removeClass('fadeOut');
      o.css('display', 'none');
      
      $('#toc.toc-aside').css('display', 'none');
        
    }
  });
});
</script>

<script type="text/javascript">
$(document).ready(function(){ 
  var ai = $('.article-content>iframe'),
      ae = $('.article-content>embed'),
      t  = $('#toc'),
      ta = $('#toc.toc-aside'),
      o  = $('.openaside'),
      c  = $('.closeaside');
  if(ai.length>0){
    ai.wrap('<div class="video-container" />');
  };
  if(ae.length>0){
   ae.wrap('<div class="video-container" />');
  };
  c.click(function(){
    ta.css('display', 'block').addClass('fadeIn');
  });
  o.click(function(){
    ta.css('display', 'none');
  });
  $(window).scroll(function(){
    ta.css("top",Math.max(140,320-$(this).scrollTop()));
  });
});
</script>


<script type="text/javascript">
$(document).ready(function(){ 
  var $this = $('.share'),
      url = $this.attr('data-url'),
      encodedUrl = encodeURIComponent(url),
      title = $this.attr('data-title'),
      tsina = $this.attr('data-tsina'),
      description = $this.attr('description');
  var html = [
  '<div class="hoverqrcode clearfix"></div>',
  '<a class="overlay" id="qrcode"></a>',
  '<a href="https://www.facebook.com/sharer.php?u=' + encodedUrl + '" class="article-share-facebook" target="_blank" title="Facebook"></a>',
  '<a href="https://twitter.com/intent/tweet?url=' + encodedUrl + '" class="article-share-twitter" target="_blank" title="Twitter"></a>',
  '<a href="#qrcode" class="article-share-qrcode" title="微信"></a>',
  '<a href="http://widget.renren.com/dialog/share?resourceUrl=' + encodedUrl + '&srcUrl=' + encodedUrl + '&title=' + title +'" class="article-share-renren" target="_blank" title="人人"></a>',
  '<a href="http://service.weibo.com/share/share.php?title='+title+'&url='+encodedUrl +'&ralateUid='+ tsina +'&searchPic=true&style=number' +'" class="article-share-weibo" target="_blank" title="微博"></a>',
  '<span title="Share to"></span>'
  ].join('');
  $this.append(html);

  $('.hoverqrcode').hide();

  var myWidth = 0;
  function updatehoverqrcode(){
    if( typeof( window.innerWidth ) == 'number' ) {
      myWidth = window.innerWidth;
    } else if( document.documentElement && document.documentElement.clientWidth) {
      myWidth = document.documentElement.clientWidth;
    };
    var qrsize = myWidth > 1024 ? 200:100;
    var options = {render: 'image', size: qrsize, fill: '#2ca6cb', text: url, radius: 0.5, quiet: 1};
    var p = $('.article-share-qrcode').position();
    $('.hoverqrcode').empty().css('width', qrsize).css('height', qrsize)
                          .css('left', p.left-qrsize/2+20).css('top', p.top-qrsize-10)
                          .qrcode(options);
  };
  $(window).resize(function(){
    $('.hoverqrcode').hide();
  });
  $('.article-share-qrcode').click(function(){
    updatehoverqrcode();
    $('.hoverqrcode').toggle();
  });
  $('.article-share-qrcode').hover(function(){}, function(){
      $('.hoverqrcode').hide();
  });
});   
</script>











<link rel="stylesheet" href="/fancybox/jquery.fancybox.css" media="screen" type="text/css">
<script src="/fancybox/jquery.fancybox.pack.js"></script>
<script type="text/javascript">
$(document).ready(function(){ 
  $('.article-content').each(function(i){
    $(this).find('img').each(function(){
      if ($(this).parent().hasClass('fancybox')) return;
      var alt = this.alt;
      if (alt) $(this).after('<span class="caption">' + alt + '</span>');
      $(this).wrap('<a href="' + this.src + '" title="' + alt + '" class="fancybox"></a>');
    });
    $(this).find('.fancybox').each(function(){
      $(this).attr('rel', 'article' + i);
    });
  });
  if($.fancybox){
    $('.fancybox').fancybox();
  }
}); 
</script>



<!-- Analytics Begin -->



<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "//hm.baidu.com/hm.js?e6d1f421bbc9962127a50488f9ed37d1";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>



<!-- Analytics End -->

<!-- Totop Begin -->

	<div id="totop">
	<a title="Back to Top"><img src="/img/scrollup.png"/></a>
	</div>
	<script src="/js/totop.js"></script>

<!-- Totop End -->

<!-- MathJax Begin -->
<!-- mathjax config similar to math.stackexchange -->


<!-- MathJax End -->

<!-- Tiny_search Begin -->

<!-- Tiny_search End -->

  </body>
</html>
